//
//  YQShareSDKManager+Login.m
//  MeiMeng
//
//  Created by weixb on 2017/3/24.
//  Copyright © 2017年 weixb. All rights reserved.
//

#import "YQShareSDKManager+Login.h"

@implementation YQShareSDKManager (Login)
/* qq */
+ (void)qqLogin:(void (^)(SSDKUser *))successBlock {
    [ShareSDK cancelAuthorize:SSDKPlatformTypeQQ];
    [[self class] doVendorLogin:SSDKPlatformTypeQQ successBlock:successBlock];
}
/* 微信 */
+ (void)wechatLogin:(void (^)(SSDKUser *))successBlock {
    [ShareSDK cancelAuthorize:SSDKPlatformTypeWechat];
    [[self class] doVendorLogin:SSDKPlatformTypeWechat successBlock:successBlock];
}
/* 新浪微博 */
+ (void)sinaWeiboLogin:(void (^)(SSDKUser *))successBlock {
    [ShareSDK cancelAuthorize:SSDKPlatformTypeSinaWeibo];
    [[self class] doVendorLogin:SSDKPlatformTypeSinaWeibo successBlock:successBlock];
}
/* Facebook */
+ (void)facebookLogin:(void (^)(SSDKUser *))successBlock {
    [ShareSDK cancelAuthorize:SSDKPlatformTypeFacebook];
    [[self class] doVendorLogin:SSDKPlatformTypeFacebook successBlock:successBlock];
}
/* Twitter */
+ (void)twitterLogin:(void (^)(SSDKUser *))successBlock {
    [ShareSDK cancelAuthorize:SSDKPlatformTypeTwitter];
    [[self class] doVendorLogin:SSDKPlatformTypeTwitter successBlock:successBlock];
}
/* Google */
+ (void)googleLogin:(void (^)(SSDKUser *))successBlock {
    [ShareSDK cancelAuthorize:SSDKPlatformTypeGooglePlus];
    [[self class] doVendorLogin:SSDKPlatformTypeGooglePlus successBlock:successBlock];
}

/**
 *  发起三方登录
 *
 *  @param platformType 登录类型
 */
+ (void)doVendorLogin:(SSDKPlatformType)platformType successBlock:(void (^)(SSDKUser *))successBlock {
    
    [ShareSDK getUserInfo:platformType conditional:nil onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {
        if (state == SSDKResponseStateSuccess)
        {
            if (successBlock) successBlock(user);
            NSLog(@"uid=%@",user.uid);
            NSLog(@"%@",user.credential);
            NSLog(@"token=%@",user.credential.token);
            NSLog(@"nickname=%@",user.nickname);
        }
        else
        {
            NSLog(@"%@",error);
        }
    }];
}

@end
